package com.xiaolin.service;

import com.xiaolin.dao.MessageContextMapper;
import com.xiaolin.pojo.MessageContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

/**
 * @author XiaoLin
 * @date 2019/2/25 10:35
 */
@Service
public class MessageContextService {

    @Autowired
    private MessageContextMapper messageContextMapper;

    /**
     * 保存信息
     *
     * @param messageContext
     */
    public void sendMC(MessageContext messageContext) {
        messageContextMapper.insert(messageContext);
    }

    /**
     * 根据mid更新所有信息为已读
     *
     * @param mid
     */
    public void upNotReadByMid(Integer mid, String uid) {
        Example e = new Example(MessageContext.class);
        Example.Criteria criteria = e.createCriteria();
        criteria.andEqualTo("mid", mid);
        criteria.andNotEqualTo("sendUid", uid);
        MessageContext mc = new MessageContext();
        mc.setViewState(0);
        messageContextMapper.updateByExampleSelective(mc, e);
    }
}
